﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Sale_Common;
using Sale_DAL;
namespace Sale_Operation
{
    public class Coder
    {
        public static string CreateCoder(EMenuList eMenu)
        {
            string strRes = "";         
            DataBase db = new DataBase();
            string strTableName = "";
            switch (eMenu)
            {
                case EMenuList.客户管理:
                    strTableName = "Customer";
                    break;
                case EMenuList.供应商管理:
                    strTableName = "Supplier"; 
                    break;
                case EMenuList.产品管理:
                    strTableName = "ProductInfo";
                    break;
                case EMenuList.进货单管理:
                    strTableName = "BuyBill";
                    break;
                case EMenuList.转账管理:
                    strTableName = "AccountRecord";
                    break;
                case EMenuList.费用_支出:
                    strTableName = "RecordList";
                    break;
                case EMenuList.销售管理:
                    strTableName = "SaleBill";
                    break;
                case EMenuList.退货管理:
                    strTableName = "ClientBackBill";
                    break;
                case EMenuList.返货管理:
                    strTableName = "MyBackBill";
                    break;

            }
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append(" SELECT ISNULL(COUNT(*),0)+1 FROM " + strTableName + " WHERE Year(CreateTime)="+System.DateTime.Now.Year.ToString()+" AND Month(CreateTime)="+System.DateTime.Now.Month+" AND Day(CreateTime)="+System.DateTime.Now.Day.ToString());
            int count = (int)SqlHelper.ExecuteScalar(db.Connection, System.Data.CommandType.Text, sbSql.ToString());
            strRes =System.DateTime.Now.ToString("yyyyMMdd")+count.ToString().PadLeft(3, '0');
            return strRes;

        }
    }
}
